#!/bin/bash
#

function check_httpd() {
    netstat -tunlp | grep httpd &> /dev/null 
    REVTAL=$?
    
    if [ $REVTAL -eq 0 ]; then 
        httpd_pid=`netstat -tunlp | grep httpd | awk '{print $NF}' | awk -F '/' '{print $1}'`
        echo "$(date +%Y-%m-%d" "%H:%M:%S) - - httpd service is running: ${httpd_pid}."
    else
        /usr/local/apache2.4.41/bin/apachectl -k start
    fi
}


while true; do
    check_httpd
    sleep 60s
done